#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
@File    :   quadratic.py
@Time    :   2024/12/26 21:49:59
@Author  :   xiangyu Chen
@Version :   1.0
@Contact :   yu112yu@sina.com
@License :   (C)Copyright 2017-2018, Liugroup-NLPR-CASIA
@Desc    :   None
'''


from math import sqrt

from utils.auto_type_checker import auto_type_checker

'''
请定义一个函数 quadratic(a, b, c)，接收 3 个参数，返回一元二次方程：
ax²+ bx + c = 0 的两个解。
'''


def quadratic(a, b, c):

    if (isinstance(a, (float, int)) != True):
        raise ValueError('a must be a number')
    if (isinstance(b, (float, int)) != True):
        raise ValueError('b must be a number')
    if (isinstance(c, (float, int)) != True):
        raise ValueError('c must be a number')
    x = b*b-4*a*c
    if (x < 0):
        return 'The equation has no real roots'
    return (-b+sqrt(x))/(2*a), (-b-sqrt(x))/(2*a)


@auto_type_checker
def auto_check_quadratic(a: [int, float], b: [int, float], c: [int, float]):  # type: ignore
    """_summary_

    Parameters
    ----------
    a : int, float]
        _description_
    b : int, float]
        _description_
    c : int, float]
        _description_

    Returns
    -------
    _type_
        _description_
    """

    x = b*b-4*a*c
    if (x < 0):
        return 'The equation has no real roots'
    return (-b+sqrt(x))/(2*a), (-b-sqrt(x))/(2*a)


print(quadratic(2, 3, 1) == (-0.5, -1.0))
print(quadratic(1, 3, -4) == (1.0, -4.0))
print((1, 2).__class__)
# 第三个参数非数字 ，报错
print(auto_check_quadratic(1, 1, '1'))
